@{
    ViewBag.Title = "CSS压缩/格式化工具";
    ViewBag.keywords = "CSS压缩/格式化工具";
    ViewBag.description = "CSS压缩/格式化工具";
}
<blockquote class="layui-elem-quote">
    <h3>CSS压缩/格式化工具</h3>
</blockquote>
<div class="layui-form">
    <div class="layui-row layui-col-space20">
        <div class="vew-row">
            <textarea id="code" class="layui-textarea textarea_0" rows=10 name="input_textarea" placeholder="输入要压缩/格式化的CSS"></textarea>
        </div>
        <div class="vew-row">
            <a class="layui-btn layui-btn-normal layui-btn-sm" onclick="CSS('packAdv');" value="高级压缩">高级压缩</a>
            <a class="layui-btn layui-btn-normal layui-btn-sm" onclick="CSS('pack');" value="普通压缩"> 普通压缩</a>
            <a class="layui-btn layui-btn-normal layui-btn-sm" onclick="CSS('format');" value="格式化">格式化</a>
            <a class="layui-btn layui-btn-primary layui-btn-sm copy" onclick="copytxt();">复制结果</a>
        </div>
        <div class="vew-row">
            <textarea id="packer" class="layui-textarea textarea_01" rows=10 name="input_textarea" placeholder="输出压缩格式化后的CSS"></textarea>
        </div>
    </div>
     <div class="layui-form-item layui-form-text">
                <div><a href="https://www.ruovea.com/detail/202005201011549.html">JS实现CSS压缩和反压缩功能</a></div>
            </div>
</div>
@section Scripts{
<script>
    var lCSSCoder={format:function(s){
        s=s.replace(/\s*([\{\}\:\;\,])\s*/g,"$1");
        s=s.replace(/;\s*;/g,";");
        s=s.replace(/\,[\s\.\#\d]*{/g,"{");
        s=s.replace(/([^\s])\{([^\s])/g,"$1 {\n\t$2");
        s=s.replace(/([^\s])\}([^\n]*)/g,"$1\n}\n$2");
        s=s.replace(/([^\s]);([^\s\}])/g,"$1;\n\t$2");
        return s},packAdv:function(s){
        s=s.replace(/\/\*(.|\n)*?\*\//g,"");
        s=s.replace(/\s*([\{\}\:\;\,])\s*/g,"$1");
        s=s.replace(/\,[\s\.\#\d]*\{/g,"{");
    s=s.replace(/;\s*;/g,";");s=s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return(s==null)?"":s[1]},pack:function(s){
        s=s.replace(/\/\*(.|\n)*?\*\//g,"");
        s=s.replace(/\s*([\{\}\:\;\,])\s*/g,"$1");
    s=s.replace(/\,[\s\.\#\d]*\{/g,"{");
    s=s.replace(/;\s*;/g,";");s=s.replace(/;\s*}/g,"}");
    s=s.replace(/([^\s])\{([^\s])/g,"$1{$2");
    s=s.replace(/([^\s])\}([^\n]s*)/g,"$1}\n$2");
    return s
    }
    };
    function CSS(s){
        document.getElementById("packer").value=lCSSCoder[s](document.getElementById("code").value)
    }    function copytxt(){ 
    var txt = document.getElementById("packer").value; if (txt === undefined || txt === '' || txt === null) {  layer.msg("没有输出内容.", { icon: 2 }); return; } if (XEClipboard.copy(txt)) { layer.msg("复制成功.", { icon: 1 }); } else { layer.msg("复制失败.", { icon: 2 }); } }
</script>
}